const { categoryAdd, categoryDelete, categoryGet } = require("../service/categoryService")

const categoryGetApi = async () => {
    return await categoryGet();
}

const categoryAddApi = async (event, req, res) => {
    const { category_name } = event;
    // 参数检查
    if (!category_name) {
        throw new Error('参数错误');
    }
    let result = await categoryAdd(category_name);
    // console.log(type, result)
    if (result.affectedRows !== 1) {
        throw new Error('数据库错误,修改失败');
    }
    return null
}

const categoryDeleteApi = async (event, req, res) => {
    const { category_id } = event;
    // 参数检查
    if (!category_id) {
        throw new Error('参数错误');
    }
    let result = await categoryDelete(category_id);
    // console.log(type, result)
    if (result.affectedRows !== 1) {
        throw new Error('数据库错误,修改失败');
    }
    return null
}

module.exports = {
    categoryGetApi,
    categoryAddApi,
    categoryDeleteApi,
}